﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL;
using DTO;

namespace BUS
{
    public class CHI_TIET_DON_HANGBUS
    {
        CHI_TIET_DON_HANGDAL kh = new CHI_TIET_DON_HANGDAL();
        public void ChiTietDonHang_Them(CHI_TIET_DON_HANG k)
        {
            kh.ChiTietDonHang_ThemDuLieu(k);
        }

        public void ChiTietDonHang_Sua(CHI_TIET_DON_HANG k)
        {
            kh.ChiTietDonHang_SuaDuLieu(k);
        }

        public void ChiTietDonHang_Xoa(string id)
        {
            kh.ChiTietDonHang_XoaDuLieu(id);
        }

        public static ChiTietDonHangCollection ChiTietDonHang_LayTatCaCSDL()
        {
            int t = 0;
            CHI_TIET_DON_HANGDAL dh = new CHI_TIET_DON_HANGDAL();
            return dh.Get("where 1=1", 0, 1000, ChiTietDonHangColumns.MA_DH.ToString(), "DESC", out t);
        }

        public static CHI_TIET_DON_HANG GetByID(int iD)
        {
            int t = 0;
            CHI_TIET_DON_HANGDAL dh = new CHI_TIET_DON_HANGDAL();
            ChiTietDonHangCollection chitietdonhangcollection = dh.Get("where " + ChiTietDonHangColumns.MA_DH.ToString() + " = " + iD.ToString(), 0, 0,
            ChiTietDonHangColumns.MA_DH.ToString(), "ASC", out t); // cần hiểu chổ này
            if (chitietdonhangcollection.Count == 1)
                return chitietdonhangcollection[0];
            return null;
        }

        //public static string GetCha(int makhachhang)
        //{
        //    int t = 0;
        //    DON_HANGDAL dh = new DON_HANGDAL();
        //    DonHangCollection donhangcollection = dh.Get("where " + DonHangColumns.MA_DH.ToString() + " = " + makhachhang.ToString(), 0, 0,
        //        DonHangColumns.MA_DH.ToString(), "ASC", out t);
        //    if (donhangcollection.Count == 1)
        //        return donhangcollection[0].MaDonHang.ToString();
        //    return null;
        //}
    }
}
